using System;
using System.Collections.Generic;
using System.Text;
using FlatRedBall;
using FlatRedBall.Input;
using FlatRedBall.AI.Pathfinding;
using FlatRedBall.Graphics.Animation;
using FlatRedBall.Graphics.Particle;

using FlatRedBall.Math.Geometry;
using FlatRedBall.Math.Splines;
using BitmapFont = FlatRedBall.Graphics.BitmapFont;
using Cursor = FlatRedBall.Gui.Cursor;
using GuiManager = FlatRedBall.Gui.GuiManager;

#if FRB_XNA || SILVERLIGHT
using Keys = Microsoft.Xna.Framework.Input.Keys;
using Vector3 = Microsoft.Xna.Framework.Vector3;
using Texture2D = Microsoft.Xna.Framework.Graphics.Texture2D;


#endif

namespace NereusGame.Entities.HBodies
{
	public partial class Planet
	{
        private float angularPosition;
        private float angularVelocity;
        private float orbitRadius;
        private float starMass;
        private float g;
        private Random rand;


		private void CustomInitialize()
		{
		}

		private void CustomActivity()
		{
            updateOrbit();
		}

		private void CustomDestroy()
		{
            base.Destroy();
		}

        private static void CustomLoadStaticContent(string contentManagerName)
        {

        }

        public void setDistanceFromStar(float orbitalRadius, float sMass, float G)
        {
            orbitRadius = orbitalRadius;
            starMass = sMass;
            g = G;
            initializeOrbit();
        }

        private void initializeOrbit()
        {
            rand = new Random();
            angularPosition = rand.Next(0, 614)/100;
            GravRange = 20;
            Mass = 3000;
            GravRing.Color = Microsoft.Xna.Framework.Color.BlanchedAlmond;
            GravRing.Radius = GravRange;
            Body.Radius = 3f;
            Texture.Texture = BrownPlanet;
            Texture.ScaleX = Texture.ScaleY = 3f;
            angularVelocity = (float)Math.Atan2(Math.Sqrt(g * starMass / orbitRadius),orbitRadius)/3;
            Position.X = (float)Math.Sin(angularPosition) * orbitRadius;
            Position.Y = (float)Math.Cos(angularPosition) * orbitRadius;
            Position.Z = 0;
        }

        private void updateOrbit()
        {
            angularPosition += angularVelocity;
            angularVelocity = (float)angularVelocity % (float)(2 * Math.PI);
            Position.X = (float)Math.Sin(angularPosition) * orbitRadius;
            Position.Y = (float)Math.Cos(angularPosition) * orbitRadius;
        }
	}
}
